package com.though.utils.tools;

import java.util.Random;

public class RandomUtil {


	/**
	 * 生成全数字
	 */
	public static String randomNumber(int length) {
		StringBuilder builder = new StringBuilder();
		Random random = new Random();  
		for (int i = 0; i < length; i++) {
			builder.append(String.valueOf(random.nextInt(10)));  
		}
		return builder.toString();
	}
	
	/**
	 * 获取指定长度的随机字符串
	 */
	public static String getRandom(int length) {
		String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}
}